<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户注册 - Cloud DMS</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui-src/dist/css/layui.css">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            font-family: 'Arial', sans-serif;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .register-container {
            width: 480px;
            padding: 40px;
            background-color: rgba(255, 255, 255, 0.95);
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(0,0,0,0.1);
            backdrop-filter: blur(10px);
        }
        .register-header {
            text-align: center;
            margin-bottom: 30px;
        }
        .register-title {
            font-size: 28px;
            font-weight: bold;
            color: #4A90E2;
            margin-bottom: 8px;
        }
        .register-subtitle {
            font-size: 14px;
            color: #666;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .user-icon {
            width: 20px;
            height: 20px;
            background: #4A90E2;
            border-radius: 50%;
            margin-right: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 12px;
        }
        .layui-form-item {
            margin-bottom: 20px;
        }
        .layui-form-label {
            width: 100px;
            font-weight: 500;
            color: #333;
        }
        .layui-input-block {
            margin-left: 120px;
        }
        .layui-input, .layui-textarea {
            height: 44px;
            line-height: 44px;
            padding: 0 15px;
            border: 2px solid #e8e8e8;
            border-radius: 8px;
            transition: border-color 0.3s;
        }
        .layui-textarea {
            height: 80px;
            line-height: 1.5;
            padding: 10px 15px;
            resize: vertical;
        }
        .layui-input:focus, .layui-textarea:focus {
            border-color: #4A90E2;
            box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
        }
        .layui-btn {
            width: 100%;
            height: 44px;
            line-height: 44px;
            background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
            border: none;
            border-radius: 8px;
            color: #fff;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
        }
        .layui-btn:hover {
            background: linear-gradient(135deg, #357ABD 0%, #2E5E95 100%);
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
        }
        .register-footer {
            text-align: center;
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        }
        .login-link {
            color: #666;
            text-decoration: none;
            font-size: 14px;
            transition: color 0.3s;
        }
        .login-link:hover {
            color: #4A90E2;
        }
        .feature-tags {
            display: flex;
            justify-content: center;
            gap: 8px;
            margin-top: 15px;
            flex-wrap: wrap;
        }
        .feature-tag {
            background: rgba(74, 144, 226, 0.1);
            color: #4A90E2;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
        }
        .tips-box {
            background: rgba(74, 144, 226, 0.1);
            border: 1px solid rgba(74, 144, 226, 0.2);
            border-radius: 6px;
            padding: 12px;
            margin-top: 15px;
        }
        .tips-text {
            color: #4A90E2;
            font-size: 12px;
            margin: 0;
            line-height: 1.4;
        }
        .password-strength {
            margin-top: 5px;
            font-size: 12px;
        }
        .strength-weak { color: #ff5722; }
        .strength-medium { color: #ff9800; }
        .strength-strong { color: #4caf50; }
    </style>
</head>
<body>
<div class="register-container layui-form" action="">
    <div class="register-header">
        <div class="register-title">Cloud DMS</div>
        <div class="register-subtitle">
            <div class="user-icon">👤</div>
            用户注册
        </div>
        <div class="feature-tags">
            <span class="feature-tag">免费注册</span>
            <span class="feature-tag">5GB空间</span>
            <span class="feature-tag">安全存储</span>
        </div>
        <div class="tips-box">
            <p class="tips-text">📝 注册即可获得5GB免费存储空间，支持文件加密、安全分享等功能</p>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" required lay-verify="required|username" placeholder="请输入用户名（3-20位字母数字）" autocomplete="off" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="email" name="email" required lay-verify="required|email" placeholder="请输入邮箱地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" id="password" required lay-verify="required|password" placeholder="请输入密码（至少6位）" autocomplete="off" class="layui-input">
            <div class="password-strength" id="password-strength"></div>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" name="confirmPassword" required lay-verify="required|confirmPassword" placeholder="请再次输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    
    
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="checkbox" name="agree" required lay-verify="required" lay-skin="primary" title="我已阅读并同意《用户协议》和《隐私政策》">
        </div>
    </div>
    
    <div class="layui-form-item">
        <button class="layui-btn" lay-submit lay-filter="user-register">立即注册</button>
    </div>
    
    <div class="register-footer">
        <a href="/auth/user-login" class="login-link">已有账号？立即登录</a>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/layui-src/dist/layui.js"></script>
<script>
    layui.use(['form', 'layer'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        // 自定义验证规则
        form.verify({
            username: function(value){
                if(!/^[a-zA-Z0-9]{3,20}$/.test(value)){
                    return '用户名必须3-20位，只能包含字母和数字';
                }
            },
            password: function(value){
                if(value.length < 6){
                    return '密码长度不能少于6位';
                }
            },
            confirmPassword: function(value){
                var password = $('#password').val();
                if(value !== password){
                    return '两次密码输入不一致';
                }
            }
        });

        // 密码强度检测
        $('#password').on('input', function(){
            var password = $(this).val();
            var strength = checkPasswordStrength(password);
            var strengthText = '';
            var strengthClass = '';
            
            if(password.length === 0){
                strengthText = '';
            } else if(strength < 3){
                strengthText = '密码强度：弱';
                strengthClass = 'strength-weak';
            } else if(strength < 5){
                strengthText = '密码强度：中等';
                strengthClass = 'strength-medium';
            } else {
                strengthText = '密码强度：强';
                strengthClass = 'strength-strong';
            }
            
            $('#password-strength').text(strengthText).attr('class', 'password-strength ' + strengthClass);
        });

        function checkPasswordStrength(password){
            var strength = 0;
            if(password.length >= 6) strength++;
            if(password.length >= 8) strength++;
            if(/[a-z]/.test(password)) strength++;
            if(/[A-Z]/.test(password)) strength++;
            if(/[0-9]/.test(password)) strength++;
            if(/[^a-zA-Z0-9]/.test(password)) strength++;
            return strength;
        }

        // 用户注册表单提交
        form.on('submit(user-register)', function(data){
            var formData = data.field;
            
            // 发送Ajax请求到服务器进行注册
            $.ajax({
                url: '/auth/register',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({
                    username: formData.username,
                    password: formData.password,
                    email: formData.email
                }),
                success: function(response) {
                    if (response.success) {
                        layer.alert(response.message, {
                            icon: 1,
                            title: '注册成功',
                            btn: ['前往登录']
                        }, function(index) {
                            window.location.href = '/auth/user-login';
                            layer.close(index);
                        });
                    } else {
                        layer.msg(response.message, {icon: 2, time: 3000});
                    }
                },
                error: function() {
                    layer.msg('网络连接异常，请稍后再试', {icon: 2, time: 3000});
                }
            });

            return false; // 阻止表单跳转
        });
    });
</script>
</body>
</html>